package com.novax.ex.activity.provider.service;

import com.novax.ex.activity.infrastructure.entity.MallServiceLanguage;
import com.novax.ex.activity.infrastructure.mapper.MallServiceLanguageMapper;
import com.novax.ex.activity.open.model.response.MallServiceLanguageResponse;
import com.novax.ex.common.base.BaseMapper;
import com.novax.ex.common.base.BaseService;
import com.novax.ex.common.enums.LanguageType;
import com.novax.ex.common.util.CopyUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.Objects;

/**
 * Description:商品规则
 *
 * @author Deucalion@novax.email
 * @date 2023/2/21 17:21
 */
@Service
public class MallServiceLanguageService extends BaseService {
    @Resource
    private MallServiceLanguageMapper mallServiceLanguageMapper;
    @Override
    protected BaseMapper getBaseMapper() {
        return mallServiceLanguageMapper;
    }

    /** 数据查重 */
    public MallServiceLanguage findByLanguage(String language){
        return mallServiceLanguageMapper.selectByLanguage(language);
    }

    /**
     * @description: 获取服务
     * @author: Wade
     * @date: 2/22/23 5:05 PM
     * @param: [language]
     * @return: com.novax.ex.activity.open.model.response.MallServiceLanguageResponse
     **/
    public MallServiceLanguageResponse service(String language) {
        MallServiceLanguage serviceLanguage = mallServiceLanguageMapper.selectByLanguage(language);
        if (Objects.nonNull(serviceLanguage)) {
            return CopyUtils.copyObject(serviceLanguage, MallServiceLanguageResponse.class);
        }else{
            MallServiceLanguage enLanguage = mallServiceLanguageMapper.selectByLanguage(LanguageType.en.getType());
            if (Objects.nonNull(enLanguage)) {
                return CopyUtils.copyObject(enLanguage, MallServiceLanguageResponse.class);
            }
        }
        return null;
    }
}
